// 导入 axios
import axios from 'axios'
// 导入 react-vant 消息模块
import { showToast } from 'vant';  

// 创建 axios 实例
const service = axios.create({
  // baseURL: 'http://localhost:3001',
  timeout: 6000,
  withCredentials: true,
})
// 请求拦截
service.interceptors.request.use(
  config => {
    config.data = JSON.stringify(config.data)
    config.headers = {
      'Content-Type': 'application/json; charset=utf-8', //配置请求头
      // 'referer': 'https://m.weibo.cn/?display=0&retcode=6102'
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 响应拦截
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    showToast(error)
  }
)

export default service
